class VideoDescriptor():

    data = None
    
    def __init__(self, data):
        self.data = data
        
    def getCodec(self):
        
        tr = {
              'default' : '???',
              'DivX v3 MPEG-4 Low-Motion (fourcc:"div3")' : 'DiV3',
              'DivX v3 MPEG-4 Low-Motion (fourcc:"DIV3")' : 'DiV3',
              #'V_MS/VFW/FOURCC' : 'DiVX',
              'DivX v4 (fourcc:"divx")' : 'DiVX',
          'DivX v3 MPEG-4 Fast-Motion (fourcc:"div4")' : 'DiVX',
          'DivX v3 MPEG-4 Fast-Motion (fourcc:"DIV4")' : 'DiVX',
          '(empty) (fourcc:"")' : 'DiVX',

              
              "XViD" : 'XViD',
              'XviD MPEG-4 (fourcc:"xvid")' : 'XViD',
              'XviD MPEG-4 (fourcc:"XVID")' : 'XViD',
              
              'V_MPEG4/ISO/AVC' : 'H264'
              }
        
        
        
        if(self.data['compression']):
            codec = self.data['compression'].strip()
            
            try:
                codec = tr[codec]
            except KeyError, err:
                print "* Video codec : '%s' is unknown, falling back to default" % codec
                print self.data
                codec = tr['default'] + '(%s)' % codec
            return codec
        
    def getQuality(self):
        """
        720p = 1280x720
        1080p = 1920x1080
        """
        
        
        w = self.getWidth()
        h = self.getHeight()
            
        if(w >= 1920):
            return 'HD1080'
        elif(w >= 1280):
            return 'HD720'
        else:
            return 'DVDRiP'

    def getWidth(self):
        w = 0
        if(self.data['width']):
            w = int(self.data['width'].strip())
        return w 

    def getHeight(self):
        h = 0
        if(self.data['height']):
            h = int(self.data['height'].strip())
        return h
